<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
	<xsl:param name="DOTNET2"/>

	<xsl:template name="replace-string">
		<xsl:param name="text"/>
		<xsl:param name="replace"/>
		<xsl:param name="with"/>
		<xsl:choose>
			<xsl:when test="contains($text,$replace)">
				<xsl:value-of select="substring-before($text,$replace)"/>
				<xsl:value-of select="$with"/>
				<xsl:call-template name="replace-string">
					<xsl:with-param name="text" select="substring-after($text,$replace)"/>
					<xsl:with-param name="replace" select="$replace"/>
					<xsl:with-param name="with" select="$with"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$text"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<xsl:template match="HeaderInfo">


using System;
using System.Collections;

namespace <xsl:value-of select="ProjectName"/>.Instance
{



	[Serializable]
	public abstract class <xsl:value-of select="ProjectName"/>InstanceObject
	{
	
		// Not modified on arraylist modifications
		public bool dirty=false;
		
		
		private Guid instanceID = Guid.Empty;
		
		public Guid InstanceID
		{
			get
			{
				if ( instanceID == Guid.Empty )
				{
					instanceID = new Guid ();
				}
				
				return instanceID;
			}
			
			set
			{
				instanceID = value;
			}
		}
	
		public int timezoneOffset;
	
		public abstract bool Validate (out string[] warning , out string[] error ) ;
		
#if(WEB)		
		public bool Save ( bool unique , Type type , <xsl:value-of select="ProjectName"/>InstanceObject obj )
		{
			if ( unique )
			{
				System.Web.HttpContext.Current.Session [ type.Name + InstanceID ] = obj;
				<xsl:value-of select="ProjectName"/>InstanceObject.AddSession ( type , InstanceID );
			} 
			else
			{
				System.Web.HttpContext.Current.Session [ type.Name ] = obj;
			}
			
			return true;
		}
		
		public <xsl:value-of select="ProjectName"/>InstanceObject Load ( bool unique , Type type )
		{

			if ( unique )
			{
				return (<xsl:value-of select="ProjectName"/>InstanceObject)
						System.Web.HttpContext.Current.Session [ type.Name + InstanceID ];
			}
			else
			{
				return (<xsl:value-of select="ProjectName"/>InstanceObject)
						System.Web.HttpContext.Current.Session [ type.Name ];
					
			}

			return null; // not implemented if we don't define WEB
		
		}
		
		
		public bool Delete ( bool unique , Type type )
		{
			if ( unique )
			{
				System.Web.HttpContext.Current.Session [ type.Name + InstanceID ] = null;
				<xsl:value-of select="ProjectName"/>InstanceObject.RemoveSession ( type , InstanceID );
				
			}
			else
			{
				System.Web.HttpContext.Current.Session [ type.Name ] = null;
			}
			
			return true;
		}		
		
		
		
		
#endif
		
		


		
		
		public <xsl:value-of select="ProjectName"/>InstanceObject ( int timezoneOffset ) {
			this.timezoneOffset = timezoneOffset;
		}
		
		
#if(WEB)

		public static bool RemoveSession ( Type type , Guid id )
		{
			ArrayList al;
			if ( System.Web.HttpContext.Current.Session [ type.Name + "_AL" ] == null )
			{
				al=new ArrayList ();
			}
			else
			{
				al  = ( ArrayList ) System.Web.HttpContext.Current.Session [ type.Name + "_AL" ];
			}
			
			al.Remove ( id );
			
			System.Web.HttpContext.Current.Session [ type.Name + "_AL" ] = al;
			
			return true;			
		}
		
		public static bool AddSession ( Type type , Guid id )
		{
			ArrayList al;
			if ( System.Web.HttpContext.Current.Session [ type.Name + "_AL" ] == null )
			{
				al=new ArrayList ();
			}
			else
			{
				al = ( ArrayList ) System.Web.HttpContext.Current.Session [ type.Name + "_AL" ];
			}
			
			al.Add ( id );
			
			System.Web.HttpContext.Current.Session [ type.Name + "_AL" ] = al;
			
			return true;
		}
		
		
		public static Guid[] GetGuidListFromSessionForType ( Type type )
		{
			ArrayList al;
			if ( System.Web.HttpContext.Current.Session [ type.Name + "_AL" ] == null )
			{
				al=new ArrayList ();
			}
			else
			{
				al = ( ArrayList ) System.Web.HttpContext.Current.Session [ type.Name + "_AL" ];
			}
			
			return ( Guid[] ) al.ToArray ( typeof ( Guid ) );
		}

#endif
		
		public <xsl:value-of select="ProjectName"/>InstanceObject () {}
	
	}
	
	
}


	</xsl:template>


</xsl:stylesheet>